﻿@{
    ViewBag.Title = "工作委托";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    var type = 'rule';
    $(function () {
        InitialPage();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#RecordgridTable').setGridWidth(e.delegateTarget.innerWidth -22);
                $("#RecordgridTable").setGridHeight($(window).height() - 139.5);

                $('#RulegridTable').setGridWidth(e.delegateTarget.innerWidth - 22);
                $("#RulegridTable").setGridHeight($(window).height() - 139.5);
            }, 200);
            e.stopPropagation();
        });
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        $("#RulegridTable").jqGridEx({
            url: "../../FlowManage/FlowDelegate/GetRulePageListJson",
            colModel: [
                { label: '主键', name: 'f_id', hidden: true },
                { label: '被委托人', name: 'f_tousername', index: "f_tousername", width: 100, align: "left" },
                {
                    label: "开始时间", name: "f_begindate", index: "f_begindate", width: 90, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd');
                    }
                },
                {
                    label: "结束时间", name: "f_enddate", index: "f_enddate", width: 90, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd');
                    }
                },
                { label: '委托人', name: 'f_createusername', index: 'f_createusername', width: 100, align: 'left' },
                {
                    label: "状态", name: "f_enabledmark", index: "f_enabledmark", width: 60, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1) {
                            return '<span  class=\"label label-success\">启用</span>';
                        } else if (rowObject.enabledmark == 0) {
                            return '<span  class=\"label label-danger\">停用</span>';
                        } else{
                            return '';
                        }
                    }
                },
                { label: '工作模板数量', name: 'f_shcemenum', index: "f_shcemenum", width: 90, align: "center" },
                {
                    label: "创建时间", name: "f_createdate", index: "f_createdate", width: 150, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
                    }
                },
                { label: "委托理由", name: "f_description", index: "f_description", width: 200, align: "left" }
            ]
        });
        $("#RecordgridTable").jqGridEx({
            colModel: [
                { label: '主键', name: 'f_id', hidden: true },
                { label: '实例主键', name: 'f_processid', hidden: true },
                { label: '规则主键', name: 'f_wfdelegateruleid', hidden: true },
                { label: '流程实例编号', name: 'f_processcode', index: "f_processcode", width: 100, align: "left" },
                { label: '流程实例标题', name: 'f_processname', index: "f_processname", width: 100, align: "left" },

                { label: '委托人', name: 'f_fromusername', index: 'f_fromusername', width: 100, align: 'left' },
                { label: '被委托人', name: 'f_tousername', index: 'f_tousername', width: 100, align: 'left' },
                {
                    label: "创建时间", name: "f_createdate", index: "f_createdate", width: 150, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        return formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
                    }
                }
            ],
            pager: "#recordgridPager",
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = { Keyword: $("#txt_Keyword").val() };
            searchGrid(queryJson);
        });
        //切换
        $('#queryCondition .dropdown-menu a').click(function () {
            type = $(this).attr('data-value');
            var _name = $(this).html();
            $('.dropdown-text').html(_name);
            $("#btn_Search").trigger('click');
        });
    }
    //查询函数
    function searchGrid(queryJson)
    {
        var _url = "", _postData = { queryJson: JSON.stringify(queryJson) }, _$jqgrid;
        $('#ruleTbale').hide();
        $('#recordTbale').hide();
        switch (type)
        {
            case 'rule':
                _url = "../../FlowManage/FlowDelegate/GetRulePageListJson";
                _$jqgrid = $("#RulegridTable");
                $('.btn-rule').show();
                $('#ruleTbale').show();
                break;
            case 'fromRecord':
                _url = "../../FlowManage/FlowDelegate/GetRecordPageListJson";
                _$jqgrid = $("#RecordgridTable");
                _postData['type'] = 1;
                $('.btn-rule').hide();
                $('#recordTbale').show();
                break;
            case 'toRecord':
                _url = "../../FlowManage/FlowDelegate/GetRecordPageListJson";
                _$jqgrid = $("#RecordgridTable");
                _postData['type'] = 2;
                $('.btn-rule').hide();
                $('#recordTbale').show();
                break;
        }
        $('#RecordgridTable').setGridWidth($(window).width() - 22);
        _$jqgrid.show();
        _$jqgrid.jqGrid('setGridParam', {
            url: _url,
            postData: _postData,
        }).trigger('reloadGrid');
    }
    //新增
    function btn_add() {
        dialogOpen({
            id: "form",
            title: '新增委托',
            url: '/FlowManage/FlowDelegate/Form',
            width: "900px",
            height: "520px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    };
    //编辑
    function btn_edit() {
        var keyValue = $("#RulegridTable").jqGridRowValue("f_id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "form",
                title: '修改委托',
                url: '/FlowManage/FlowDelegate/Form?keyValue=' + keyValue,
                width: "900px",
                height: "520px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#RulegridTable").jqGridRowValue("f_id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../FlowManage/FlowDelegate/DeleteRule",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#RulegridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的表单模板！', 0);
        }
    }
    //禁用
    function btn_disabled() {
        var keyValue = $("#RulegridTable").jqGridRowValue("f_id");
        if (keyValue) {
            $.ConfirmAjax({
                msg: "请确认是否要【停用】委托规则？",
                url: "../../FlowManage/FlowDelegate/UpdateRuleEnable",
                param: { keyValue: keyValue, enableMark: 0 },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择要停用的委托规则！', 0);
        }
    }
    //启用
    function btn_enabled() {
        var keyValue = $("#RulegridTable").jqGridRowValue("f_id");
        if (keyValue) {
            $.ConfirmAjax({
                msg: "请确认是否要【启用】委托规则？",
                url: "../../FlowManage/FlowDelegate/UpdateRuleEnable",
                param: { keyValue: keyValue, enableMark: 1 },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择要启用的委托规则！', 0);
        }
    }
</script>
<div class="titlePanel">
    <div class="title-search">
        <table>
            <tr>
                <td>
                    <div id="queryCondition" class="btn-group">
                        <a class="btn btn-default dropdown-text" data-toggle="dropdown">我的委托规则</a>
                        <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a data-value="rule">我的委托规则</a></li>
                            <li><a data-value="fromRecord">我的委托记录</a></li>
                            <li><a data-value="toRecord">被委托记录</a></li>
                        </ul>
                    </div>
                </td>
                <td style="padding-left: 5px;">
                    <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                </td>
                <td style="padding-left: 5px;">
                    <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="toolbar">
        <div class="btn-group">
            <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
            <a id="lr-add" class="btn btn-default btn-rule" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
            <a id="lr-edit" class="btn btn-default btn-rule" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
            <a id="lr-delete" class="btn btn-default btn-rule" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
        </div>
        <div class="btn-group btn-rule">
            <a id="lr-disabled" class="btn btn-default" onclick="btn_disabled()"><i class="fa fa-stop"></i>&nbsp;停用</a>
            <a id="lr-enabled" class="btn btn-default" onclick="btn_enabled()"><i class="fa fa-play"></i>&nbsp;启用</a>
        </div>
    </div>
</div>
<div class="gridPanel">
    <div id="ruleTbale">
        <table id="RulegridTable"></table>
        <div id="gridPager"></div>
    </div>
    <div id="recordTbale" style="display:none;">
        <table id="RecordgridTable"></table>
        <div id="recordgridPager"></div>
    </div>
</div>

